#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author: zzll0909
# @file: 13.py
# @time: 2023/6/25
# @software: PyCharm

class Solution:
    def romanToInt(self, s: str) -> int:
        roman = {
            "I": 1,
            "IV": 4,
            "V": 5,
            "IX": 9,
            "X": 10,
            "XL": 40,
            "L": 50,
            "XC": 90,
            "C": 100,
            "CD": 400,
            "D": 500,
            "CM": 900,
            "M": 1000,
        }
        result = 0
        i = 0
        while i < len(s):
            roman_num = str()
            if i <= len(s) - 2:
                roman_num = s[i:i + 2]
            if roman_num in roman.keys():
                i += 1
            else:
                roman_num = s[i:i + 1]
            result += roman[roman_num]
            i += 1
        return result


if __name__ == "__main__":
    solu = Solution()
    result = solu.romanToInt("MCMXCIV")
    print(result)
